Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
16 / 16 |
CRAP | |
100.00% |
39 / 39 |
User | |
100.00% |
1 / 1 |
|
100.00% |
16 / 16 |
19 | |
100.00% |
39 / 39 |
getisActive | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
setIsActive | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
getId | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
setId | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
getName | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
setName | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
getEmail | |
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
|||
setEmail | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
getPassword | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
setPassword | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
__construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
register | |
100.00% |
1 / 1 |
1 | |
100.00% |
4 / 4 |
|||
find | |
100.00% |
1 / 1 |
2 | |
100.00% |
9 / 9 |
|||
isActive | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
isWait | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
verify | |
100.00% |
1 / 1 |
2 | |
100.00% |
6 / 6 |
<?php | |
/** | |
* Created by PhpStorm. | |
* User: Viktor | |
* Date: 01.05.2019 | |
* Time: 16:29 | |
*/ | |
namespace App\Models; | |
use InvalidArgumentException; | |
class User | |
{ | |
public const STATUS_WAIT = '0'; | |
public const STATUS_ACTIVE = '1'; | |
private $name; | |
private $email; | |
private $password; | |
private $isActive; | |
private $id; | |
private $db; | |
/** | |
* @return mixed | |
*/ | |
public function getisActive() | |
{ | |
return $this->isActive; | |
} | |
/** | |
* @param mixed $isActive | |
*/ | |
public function setIsActive($isActive) | |
{ | |
$this->isActive = $isActive; | |
} | |
/** | |
* @return mixed | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/** | |
* @param mixed $id | |
*/ | |
public function setId($id) | |
{ | |
$this->id = $id; | |
} | |
/** | |
* @return mixed | |
*/ | |
public function getName() | |
{ | |
return $this->name; | |
} | |
/** | |
* @param mixed $name | |
*/ | |
public function setName($name) | |
{ | |
$this->name = $name; | |
} | |
/** | |
* | |
* @return mixed | |
*/ | |
public function getEmail() | |
{ | |
//@codeCoverageIgnoreStart | |
if(empty($this->email)) { | |
throw new InvalidArgumentException("message",10); | |
} | |
//@codeCoverageIgnoreEnd | |
return $this->email; | |
} | |
/** | |
* @param mixed $email | |
*/ | |
public function setEmail($email) | |
{ | |
$this->email = $email; | |
} | |
/** | |
* @return mixed | |
*/ | |
public function getPassword() | |
{ | |
return $this->password; | |
} | |
/** | |
* @param mixed $pass | |
*/ | |
public function setPassword($password) | |
{ | |
$this->password = $password; | |
} | |
public function __construct() | |
{ | |
$this->db = Db::get_instance(); | |
$this->db->setConnection('localhost','root','','phpunit'); | |
} | |
public function register ($name, $email, $password) { | |
$sql = "INSERT INTO users SET name='".$name."',email='".$email."',password='".md5($password)."'"; | |
$this->db->query($sql); | |
$this->setId($this->db->getlastId()); | |
return $this->find($this->getId()); | |
} | |
public function find($id) { | |
$sql = "SELECT * FROM users WHERE id = '" . $id ."' LIMIT 1"; | |
$result = $this->db->query($sql); | |
if($result) { | |
$row = $result->fetch_array(); | |
$this->setName($row['name']); | |
$this->setPassword($row['password']); | |
$this->setEmail($row['email']); | |
$this->setIsActive($row['is_active']); | |
} | |
return $this; | |
} | |
public function isActive(): bool | |
{ | |
return $this->getIsActive() === self::STATUS_ACTIVE; | |
} | |
public function isWait(): bool | |
{ | |
return $this->getIsActive() === self::STATUS_WAIT; | |
} | |
public function verify(): void | |
{ | |
if (!$this->isWait()) { | |
throw new \Exception('User verified'); | |
} | |
$sql = "UPDATE users SET is_active='".self::STATUS_ACTIVE."' WHERE id = '" . $this->getId() . "'"; | |
$this->db->query($sql); | |
$this->setIsActive(self::STATUS_ACTIVE); | |
} | |
} |